package com.hundsun.yr.universal.p2p.presenter.impl;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;

import com.hundsun.mobile.zwgt.R;
import com.hundsun.yr.universal.library.common.MD5Utils;
import com.hundsun.yr.universal.library.data.HSSharedPreferences;
import com.hundsun.yr.universal.library.eventbus.EventCenter;
import com.hundsun.yr.universal.library.netstatus.NetUtils;
import com.hundsun.yr.universal.library.utils.MathUtils;
import com.hundsun.yr.universal.library.utils.RegularUtils;
import com.hundsun.yr.universal.library.widget.HSToast;
import com.hundsun.yr.universal.p2p.bean.AdSlideBeen;
import com.hundsun.yr.universal.p2p.bean.LoginBeen;
import com.hundsun.yr.universal.p2p.bean.UserInfo;
import com.hundsun.yr.universal.p2p.config.Config;
import com.hundsun.yr.universal.p2p.config.Constants;
import com.hundsun.yr.universal.p2p.config.TaskConstants;
import com.hundsun.yr.universal.p2p.interactor.base.RequestInteractor;
import com.hundsun.yr.universal.p2p.interactor.impl.StringRequestGetInteractorImpl;
import com.hundsun.yr.universal.p2p.interactor.impl.StringRequestInteractorImpl;
import com.hundsun.yr.universal.p2p.listener.BaseMultiLoadedListener;
import com.hundsun.yr.universal.p2p.presenter.base.LoginPresenter;
import com.hundsun.yr.universal.p2p.ui.activity.LoginActivity;
import com.hundsun.yr.universal.p2p.utils.AndroidDes3Util;
import com.hundsun.yr.universal.p2p.utils.BaseRequestTool2;
import com.hundsun.yr.universal.p2p.utils.CommTool;
import com.hundsun.yr.universal.p2p.utils.GsonTool;
import com.hundsun.yr.universal.p2p.utils.Logs;
import com.hundsun.yr.universal.p2p.view.LoginView;

import org.json.JSONException;
import org.json.JSONObject;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.TimeZone;

import de.greenrobot.event.EventBus;

/**
 * @version V1.0
 * @Title: LoginPresenterImpl.java
 * @Description: 登陆业务逻辑
 * @date 2016-1-19 上午10:13:56
 * @author:hejun.shen
 * @email:shenhj15971@hundsun.com
 * @replace author:
 * @replace date:
 */
public class LoginPresenterImpl implements LoginPresenter, BaseMultiLoadedListener<String> {

    private Context mContext = null;
    private LoginView mLoginView = null;
    /**
     * 请求接口
     **/
    private RequestInteractor mInteractor = null;
    private RequestInteractor mInteractorGet = null;
    /**
     * 用户信息sp文件
     **/
    private HSSharedPreferences hsSharedPreferences = null;
    /**用户临时信息sp文件**/
//	private HSSharedPreferences hsTemporarySp=null;
    /**
     * 存储用户信息
     **/
    public HSSharedPreferences mConfigSP = null;

    public LoginPresenterImpl(Context context, LoginView loginView) {
        if (null == loginView) {
            throw new IllegalArgumentException("Constructor's parameters must not be Null");
        }
        hsSharedPreferences = new HSSharedPreferences(context, Config.SPPath.file_userLoginedInfo);
        mConfigSP = new HSSharedPreferences(context, Config.SPPath.file_configInfo);

        mContext = context;
        mLoginView = loginView;
        this.mInteractor = new StringRequestInteractorImpl(this);
        this.mInteractorGet = new StringRequestGetInteractorImpl(this);
    }

    @Override
    public void initialized() {
        // TODO Auto-generated method stub
        hsSharedPreferences.putBoolean(UserInfo.ISLOGIN, false);
    }

    /**
     * 继承自LoginPresenter，用于用户登录
     *
     * @param username
     * @param password
     */
    @Override
    public void validateCredentials(String username, String password) throws JSONException {
        // TODO Auto-generated method stub

        if (TextUtils.isEmpty(username)) {
            mLoginView.showValidateError(mContext.getString(R.string.empty_phone_number));
            return;
        }

        if (TextUtils.isEmpty(password)) {
            mLoginView.showValidateError(mContext.getString(R.string.empty_pwd));
            return;
        }

//		if(!RegularUtils.regular(RegularUtils.REGEX_PWD, password)){
//			mLoginView.showValidateError("您输入的密码格式不正确");
//			return ;
//		}

        if (!RegularUtils.isPhoneNum(username)) {
            mLoginView.showValidateError(mContext.getString(R.string.error_phone_number));
            return;
        }

        /**
         * 登录接口的请求
         */
        //时间
        String zwgt_data = BaseRequestTool2.getFormatedDateString();
        JSONObject map = new JSONObject();
        try {
            map.put("phone", username);
            map.put("passwd", MD5Utils.getMD5String(password));
        } catch (JSONException e) {
            e.printStackTrace();
        }
        JSONObject jsonParams = CommTool.getJSONParams(map, ((LoginActivity) mLoginView).mConfigSP.getShareProf(TaskConstants.TASK_CONFIG), zwgt_data);
        loadingData(TaskConstants.TASK_LOGIN, mContext.getString(R.string.root_url_test) + mContext.getString(R.string.api_index_test) + TaskConstants.TASK_LOGIN, Constants.EVENT_DATA, jsonParams
                , BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_POST, mContext.getString(R.string.api_index_test) + TaskConstants.TASK_LOGIN, "", mConfigSP.getShareProf(TaskConstants.TASK_CONFIG), zwgt_data), false);
    }

    /**
     * 忘记密码
     */
    @Override
    public void forgetPwd() {
/*		// TODO 判断手机号
        if(!TextUtils.isEmpty(username)&&RegularUtils.isPhoneNum(username)){
			mLoginView.navigateForgetPassword(username);
		}else{
			mLoginView.navigateForgetPassword("");
		}*/
        mLoginView.navigateForgetPassword();
    }

    @Override
    public void regiester() {
        // TODO Auto-generated method stub
        mLoginView.navigateToRegiester();
    }

    @Override
    public void onSuccess(String task_name, int event_tag, String data) throws Exception {
        mLoginView.closeProgress();
        try {
            AdSlideBeen adSlideBeen = (AdSlideBeen) GsonTool.getInstanceByJson(AdSlideBeen.class, data);
            switch (task_name) {
                case TaskConstants.TASK_LOGIN:
                    //登录的接口
                    //数据请求成功之后对数据进行解密存储等操作
                    switch (adSlideBeen.code) {
                        case Constants.REQUESTCODE_000000:
                            //对data进行解密
                            try {
                                String decode = AndroidDes3Util.decode(adSlideBeen.data, mConfigSP.getShareProf(TaskConstants.TASK_CONFIG),
                                        (Date.parse(adSlideBeen.timestamp) + "").substring((Date.parse(adSlideBeen.timestamp) + "").length() - 8, (Date.parse(adSlideBeen.timestamp) + "").length()));
                                String[] split = decode.split("\\n");

                                if (split[1].isEmpty()) {
                                    new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.login_error)).show();
                                    hsSharedPreferences.putBoolean(UserInfo.ISLOGIN, false);
                                    return;
                                }
                                //解密成功，循环写入json数组中
                                LoginBeen loginBeen = (LoginBeen) GsonTool.getInstanceByJson(LoginBeen.class, split[1]);

                                //将获得的数据存起来
                                //存放token

                                if (UserInfo.TOKENID == null || UserInfo.TOKENID.isEmpty()) {
                                    new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.login_error)).show();
                                    return;
                                }

                                hsSharedPreferences.putShareProf(UserInfo.TOKENID, loginBeen.token);

                                if (UserInfo.USER_NO == null || UserInfo.USER_NO.isEmpty()) {
                                    new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.login_error)).show();
                                    return;
                                }

                                //存放用户id
                                hsSharedPreferences.putShareProf(UserInfo.USER_NO, loginBeen.user_no);

                                //存放用户手机号
                                hsSharedPreferences.putShareProf(UserInfo.MOBILE, loginBeen.phone);

                                //存放账号，应该就是手机号
                                hsSharedPreferences.putShareProf(UserInfo.ACCOUNT, loginBeen.phone);

                                //身份证
                                hsSharedPreferences.putShareProf(UserInfo.CERT_NO, loginBeen.cert_no);

                                hsSharedPreferences.putShareProf(UserInfo.REALNAME, loginBeen.true_name);

                                hsSharedPreferences.putShareProf(UserInfo.LENDER, loginBeen.is_lender);
                                /**
                                 * 保存用户开户状态
                                 */
                                if (loginBeen.depository_bank_no != null && !loginBeen.depository_bank_no.isEmpty()) {
                                    //已开户
                                    hsSharedPreferences.putShareProf(UserInfo.IF_ACCOUNT, "YES");
                                } else {
                                    //已开户
                                    hsSharedPreferences.putShareProf(UserInfo.IF_ACCOUNT, "NO");
                                    new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.open_account)).show();
                                }

                                /**
                                 * 用户是否设置了交易密码
                                 */
                                if (loginBeen.set_paypwd_flag != null && !loginBeen.set_paypwd_flag.isEmpty()) {
                                    if (TextUtils.equals(loginBeen.set_paypwd_flag, "1")) {
                                        //已经设置交易密码
                                        hsSharedPreferences.putShareProf(UserInfo.IF_PAYPWD, "YES");
                                    } else {
                                        hsSharedPreferences.putShareProf(UserInfo.IF_PAYPWD, "NO");
                                    }
                                } else {
                                    hsSharedPreferences.putShareProf(UserInfo.IF_PAYPWD, "NO");
                                }

                                /**
                                 * 保存用户等级
                                 */
                                if (loginBeen.level != null && !loginBeen.level.isEmpty()) {
                                    hsSharedPreferences.putShareProf(UserInfo.USERLEVEL, loginBeen.level);
                                } else {
                                    hsSharedPreferences.putShareProf(UserInfo.USERLEVEL, "0");
                                }

                                if (loginBeen.ifBindcard != null && !loginBeen.ifBindcard.isEmpty()) {
                                    if (TextUtils.equals(loginBeen.ifBindcard, "1")) {
                                        hsSharedPreferences.putShareProf(UserInfo.IF_BINDCARD, "YES");
                                    } else {
                                        hsSharedPreferences.putShareProf(UserInfo.IF_BINDCARD, "NO");
                                    }
                                } else {
                                    hsSharedPreferences.putShareProf(UserInfo.IF_BINDCARD, "NO");
                                }


                                /**
                                 * 保存用户银行卡手机号
                                 */
                                if (loginBeen.depository_bank_mobile != null && !loginBeen.depository_bank_mobile.isEmpty()) {
                                    hsSharedPreferences.putShareProf(UserInfo.BANKMOBILE, loginBeen.depository_bank_mobile);
                                } else {
                                    hsSharedPreferences.putShareProf(UserInfo.BANKMOBILE, "");
                                }

                                /**
                                 * 判断是否老用户
                                 */
                                if (loginBeen.ctime != null && !loginBeen.ctime.isEmpty()) {
                                    //将时间转换成时间戳
                                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//24小时制
                                    //      SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh-mm-ss");//12小时制
                                    simpleDateFormat.setTimeZone(TimeZone.getTimeZone("GMT+8"));

                                    long time = simpleDateFormat.parse(loginBeen.ctime).getTime();
                                    if (MathUtils.compare(time + "", "1498147200000") <= 0) {
                                        //老用户
                                        hsSharedPreferences.putBoolean(UserInfo.OLDUSER, true);
                                    } else {
                                        hsSharedPreferences.putBoolean(UserInfo.OLDUSER, false);
                                    }
                                } else {
                                    hsSharedPreferences.putBoolean(UserInfo.OLDUSER, false);
                                }

                                if (loginBeen.unread != null && !loginBeen.unread.isEmpty()) {
                                    hsSharedPreferences.putShareProf(UserInfo.UNREAD, loginBeen.unread);
                                } else {
                                    hsSharedPreferences.putShareProf(UserInfo.UNREAD, "0");
                                }

                                //保存用户年龄
                                if (loginBeen.old != null && !loginBeen.old.isEmpty()) {
                                    hsSharedPreferences.putShareProf(UserInfo.OLD, loginBeen.old);
                                } else {
                                    hsSharedPreferences.putShareProf(UserInfo.OLD, "");
                                }

                                hsSharedPreferences.putBoolean(UserInfo.ISLOGIN, true);
                                mConfigSP.putBoolean(UserInfo.BANK_ACCOUNT_INTERFACE_SUCCESS, false);
                                mLoginView.navigateToHomePage();
                            } catch (Exception e) {
                                e.printStackTrace();
                                new HSToast(mContext).showToast(mContext.getString(R.string.login_error));
                            }
                            break;
                        case Constants.REQUESTCODE_200000:
                            //用户名或者密码错误
                            new HSToast(mContext).showToast(mContext.getString(R.string.loginFail));
                            break;
                        case Constants.REQUESTCODE_100020:
                            //Header值为空--不做任何提示
                            break;
                        case Constants.REQUESTCODE_100010:
                            break;
                        default:
                            new HSToast(mContext).showCustomToast(adSlideBeen.msg);
                            break;
                    }
                    break;
                case TaskConstants.TASK_SENDSMS://获取登陆验证码
                    switch (adSlideBeen.code) {
                        case Constants.REQUESTCODE_000000:
                        case Constants.REQUESTCODE_400001:
                            try {
//								String decode = AndroidDes3Util.decode(adSlideBeen.data, mConfigSP.getShareProf("config"), (Date.parse(adSlideBeen.timestamp) + "").substring((Date.parse(adSlideBeen.timestamp) + "").length() - 8, (Date.parse(adSlideBeen.timestamp) + "").length()));
//								String[] split = decode.split("\\n");
                                new HSToast(mContext).showCustomToast(adSlideBeen.msg);
                                mLoginView.initializeViews(TaskConstants.TASK_SENDSMS);
                            } catch (Exception e) {
                                e.printStackTrace();
                                new HSToast(mContext).showToast(mContext.getString(R.string.date_error));
                            }
                            break;
                        case Constants.REQUESTCODE_100020:
                            //Header值为空--不做任何提示
                            break;
                        case Constants.REQUESTCODE_100010:
                            break;
                        default:
                            new HSToast(mContext).showCustomToast(adSlideBeen.msg);
                            break;
                    }
                    break;

                case TaskConstants.TASK_LOGINBYSMS://通过验证码登陆
                    switch (adSlideBeen.code) {
                        case Constants.REQUESTCODE_000000:
                            try {
                                //对data进行解密
                                String decode = AndroidDes3Util.decode(adSlideBeen.data, mConfigSP.getShareProf(TaskConstants.TASK_CONFIG),
                                        (Date.parse(adSlideBeen.timestamp) + "").substring((Date.parse(adSlideBeen.timestamp) + "").length() - 8, (Date.parse(adSlideBeen.timestamp) + "").length()));
                                String[] split = decode.split("\\n");
                                if (split[1].isEmpty()) {
                                    new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.login_error)).show();
                                    hsSharedPreferences.putBoolean(UserInfo.ISLOGIN, false);
                                    return;
                                }
                                //解密成功，循环写入json数组中
                                LoginBeen loginBeen = (LoginBeen) GsonTool.getInstanceByJson(LoginBeen.class, split[1]);
                                //将获得的数据存起来
                                //存放token
                                if (UserInfo.TOKENID == null || UserInfo.TOKENID.isEmpty()) {
                                    new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.login_error)).show();
                                    return;
                                }


                                hsSharedPreferences.putShareProf(UserInfo.TOKENID, loginBeen.token);

                                if (UserInfo.USER_NO == null || UserInfo.USER_NO.isEmpty()) {
                                    new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.login_error)).show();
                                    return;
                                }
                                //存放用户id
                                hsSharedPreferences.putShareProf(UserInfo.USER_NO, loginBeen.user_no);

                                //存放用户手机号
                                hsSharedPreferences.putShareProf(UserInfo.MOBILE, loginBeen.phone);

                                //存放账号，应该就是手机号
                                hsSharedPreferences.putShareProf(UserInfo.ACCOUNT, loginBeen.phone);

                                //身份证
                                hsSharedPreferences.putShareProf(UserInfo.CERT_NO, loginBeen.cert_no);

                                hsSharedPreferences.putShareProf(UserInfo.REALNAME, loginBeen.true_name);
                                hsSharedPreferences.putShareProf(UserInfo.LENDER, loginBeen.is_lender);
                                /**
                                 * 保存用户开户状态
                                 */
                                if (loginBeen.depository_bank_no != null && !loginBeen.depository_bank_no.isEmpty()) {
                                    //已开户
                                    hsSharedPreferences.putShareProf(UserInfo.IF_ACCOUNT, "YES");
                                } else {
                                    //已开户
                                    hsSharedPreferences.putShareProf(UserInfo.IF_ACCOUNT, "NO");
                                    new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.open_account)).show();
                                }

                                /**
                                 * 用户是否设置了交易密码
                                 */
                                if (loginBeen.set_paypwd_flag != null && !loginBeen.set_paypwd_flag.isEmpty()) {
                                    if (TextUtils.equals(loginBeen.set_paypwd_flag, "1")) {
                                        //已经设置交易密码
                                        hsSharedPreferences.putShareProf(UserInfo.IF_PAYPWD, "YES");
                                    } else {
                                        hsSharedPreferences.putShareProf(UserInfo.IF_PAYPWD, "NO");
                                    }
                                } else {
                                    hsSharedPreferences.putShareProf(UserInfo.IF_PAYPWD, "NO");
                                }

                                /**
                                 * 保存用户等级
                                 */
                                if (loginBeen.level != null && !loginBeen.level.isEmpty()) {
                                    hsSharedPreferences.putShareProf(UserInfo.USERLEVEL, loginBeen.level);
                                } else {
                                    hsSharedPreferences.putShareProf(UserInfo.USERLEVEL, "0");
                                }

                                /**
                                 * 保存用户银行卡手机号
                                 */

                                if (loginBeen.depository_bank_mobile != null && !loginBeen.depository_bank_mobile.isEmpty()) {
                                    hsSharedPreferences.putShareProf(UserInfo.BANKMOBILE, loginBeen.depository_bank_mobile);
                                } else {
                                    hsSharedPreferences.putShareProf(UserInfo.BANKMOBILE, "");
                                }

                                /**
                                 * 判断是否老用户
                                 */
                                if (loginBeen.ctime != null && !loginBeen.ctime.isEmpty()) {
                                    //将时间转换成时间戳
                                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//24小时制
                                    //      SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh-mm-ss");//12小时制
                                    simpleDateFormat.setTimeZone(TimeZone.getTimeZone("GMT+8"));
                                    long time = simpleDateFormat.parse(loginBeen.ctime).getTime();
                                    if (MathUtils.compare(time + "", "1498147200000") <= 0) {
                                        //老用户
                                        hsSharedPreferences.putBoolean(UserInfo.OLDUSER, true);
                                    } else {
                                        hsSharedPreferences.putBoolean(UserInfo.OLDUSER, false);
                                    }
                                } else {
                                    hsSharedPreferences.putBoolean(UserInfo.OLDUSER, false);
                                }

                                if (loginBeen.unread != null && !loginBeen.unread.isEmpty()) {
                                    hsSharedPreferences.putShareProf(UserInfo.UNREAD, loginBeen.unread);
                                } else {
                                    hsSharedPreferences.putShareProf(UserInfo.UNREAD, "0");
                                }

                                //保存用户年龄
                                if (loginBeen.old != null && !loginBeen.old.isEmpty()) {
                                    hsSharedPreferences.putShareProf(UserInfo.OLD, loginBeen.old);
                                } else {
                                    hsSharedPreferences.putShareProf(UserInfo.OLD, "");
                                }

                                hsSharedPreferences.putBoolean(UserInfo.ISLOGIN, true);
                                mConfigSP.putBoolean(UserInfo.BANK_ACCOUNT_INTERFACE_SUCCESS, false);
                                mLoginView.navigateToHomePage();
                            } catch (Exception e) {
                                e.printStackTrace();
                                new HSToast(mContext).showToast(mContext.getString(R.string.login_error));
                            }

                            break;
                        case Constants.REQUESTCODE_200000:
                            //用户名或者密码错误
                            new HSToast(mContext).showToast(mContext.getString(R.string.loginFail));
                            break;

                        case Constants.REQUESTCODE_100020:
                            //Header值为空--不做任何提示
                            break;
                        case Constants.REQUESTCODE_100010:
                            break;
                        default:
                            new HSToast(mContext).showCustomToast(adSlideBeen.msg);
                            break;
                    }
                    break;

                //注册逻辑
                case TaskConstants.TASK_REGISTER:
                    switch (adSlideBeen.code) {
                        case Constants.REQUESTCODE_000000:
                            //网络请求成功,进行解密，存储相关数据
                            try {
                                new HSToast(mContext).getSingleLongToast(adSlideBeen.msg).show();
                                String decode = AndroidDes3Util.decode(adSlideBeen.data, mConfigSP.getShareProf(TaskConstants.TASK_CONFIG),
                                        (Date.parse(adSlideBeen.timestamp) + "").substring((Date.parse(adSlideBeen.timestamp) + "").length() - 8, (Date.parse(adSlideBeen.timestamp) + "").length()));
                                String[] split = decode.split("\\n");

                                LoginBeen loginBeen = (LoginBeen) GsonTool.getInstanceByJson(LoginBeen.class, split[1]);
                                //将获得的数据存起来
                                //存放token
                                hsSharedPreferences.putShareProf(UserInfo.TOKENID, loginBeen.token);
                                hsSharedPreferences.putBoolean(UserInfo.ISLOGIN, true);
                                //存放用户id
                                hsSharedPreferences.putShareProf(UserInfo.USER_NO, loginBeen.user_no);
                                //存放用户手机号
                                hsSharedPreferences.putShareProf(UserInfo.MOBILE, loginBeen.phone);
                                //存放账号，应该就是手机号
                                hsSharedPreferences.putShareProf(UserInfo.ACCOUNT, loginBeen.phone);
                                //身份证
                                hsSharedPreferences.putShareProf(UserInfo.CERT_NO, loginBeen.cert_no);
                                hsSharedPreferences.putShareProf(UserInfo.LENDER, loginBeen.is_lender);
                                if (loginBeen.depository_bank_no != null && !loginBeen.depository_bank_no.isEmpty()) {
                                    //已开户
                                    hsSharedPreferences.putShareProf(UserInfo.IF_ACCOUNT, "YES");
                                } else {
                                    //已开户
                                    hsSharedPreferences.putShareProf(UserInfo.IF_ACCOUNT, "NO");
                                }

                                /**
                                 * 用户是否设置了交易密码
                                 */
                                if (loginBeen.set_paypwd_flag != null && !loginBeen.set_paypwd_flag.isEmpty()) {
                                    if (TextUtils.equals(loginBeen.set_paypwd_flag, "1")) {
                                        //已经设置交易密码
                                        hsSharedPreferences.putShareProf(UserInfo.IF_PAYPWD, "YES");
                                    } else {
                                        hsSharedPreferences.putShareProf(UserInfo.IF_PAYPWD, "NO");
                                    }
                                } else {
                                    hsSharedPreferences.putShareProf(UserInfo.IF_PAYPWD, "NO");
                                }

                                /**
                                 * 保存用户等级
                                 */
                                if (loginBeen.level != null && !loginBeen.level.isEmpty()) {
                                    hsSharedPreferences.putShareProf(UserInfo.USERLEVEL, loginBeen.level);
                                } else {
                                    hsSharedPreferences.putShareProf(UserInfo.USERLEVEL, "0");
                                }

                                /**
                                 * 保存用户银行卡手机号
                                 */
                                if (loginBeen.depository_bank_mobile != null && !loginBeen.depository_bank_mobile.isEmpty()) {
                                    hsSharedPreferences.putShareProf(UserInfo.BANKMOBILE, loginBeen.depository_bank_mobile);
                                } else {
                                    hsSharedPreferences.putShareProf(UserInfo.BANKMOBILE, "");
                                }

                                if (loginBeen.ctime != null && !loginBeen.ctime.isEmpty()) {
                                    //将时间转换成时间戳
                                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//24小时制
                                    //      SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh-mm-ss");//12小时制
                                    simpleDateFormat.setTimeZone(TimeZone.getTimeZone("GMT+8"));
                                    long time = simpleDateFormat.parse(loginBeen.ctime).getTime();
                                    if (MathUtils.compare(time + "", "1498147200000") <= 0) {
                                        //老用户
                                        hsSharedPreferences.putBoolean(UserInfo.OLDUSER, true);
                                    } else {
                                        hsSharedPreferences.putBoolean(UserInfo.OLDUSER, false);
                                    }
                                } else {
                                    hsSharedPreferences.putBoolean(UserInfo.OLDUSER, false);
                                }

                                if (loginBeen.unread != null && !loginBeen.unread.isEmpty()) {
                                    hsSharedPreferences.putShareProf(UserInfo.UNREAD, loginBeen.unread);
                                } else {
                                    hsSharedPreferences.putShareProf(UserInfo.UNREAD, "0");
                                }

//								hsSharedPreferences.putBoolean(UserInfo.FIRST_LOGIN,true);

                                mLoginView.initializeViews(TaskConstants.TASK_REGISTER);
                            } catch (Exception e) {
                                new HSToast(mContext).getSingleLongToast(mContext.getString(R.string.date_error)).show();
                                e.printStackTrace();
                            }
                            break;
                        case Constants.REQUESTCODE_100020:
                            //Header值为空--不做任何提示
                            break;
                        default:
                            new HSToast(mContext).getSingleLongToast(adSlideBeen.msg).show();
                            break;
                    }
                    break;
            }
        } catch (Exception e) {
            new HSToast(mContext).showToast(mContext.getString(R.string.login_error));
        }
    }

    @Override
    public void onException(String task_name, String msg) {
        mLoginView.closeProgress();
        new HSToast(mContext).showToast(msg);
    }

    /**
     * 验证token
     *
     * @param token
     * @param usertype
     */
    @Override
    public void validateToken(String token, String usertype) {
        // TODO Auto-generated method stub
        if (TextUtils.isEmpty(token)) {
            mLoginView.showValidateError("token为空");
            return;
        }

        if (TextUtils.isEmpty(usertype)) {
            mLoginView.showValidateError("用户类型为空");
            return;
        }
    }

    /**
     * 网络请求params|header
     *
     * @param task_name      任务名
     * @param url            请求地址
     * @param event_tag      加载事件{@link Constants}}
     * @param params         参数
     * @param isSwipeRefresh 是否刷新
     */
    @Override
    public void loadingData(String task_name, String url, int event_tag, HashMap<String, String> params, boolean isSwipeRefresh) {
        if (NetUtils.isNetworkConnected(mContext)) {
            mLoginView.showProgress("");
            mInteractorGet.getRequestData(task_name, url, event_tag, params);
        } else {
            mLoginView.closeProgress();
            new HSToast(mContext).showToast(R.string.common_no_network);
        }
    }

    /**
     * 这种请求类型带header+params
     *
     * @param task_name
     * @param url
     * @param event_tag
     * @param params
     * @param header
     * @param isSwipeRefresh
     */
    @Override
    public void loadingData(String task_name, String url, int event_tag, HashMap<String, String> params, HashMap<String, String> header, boolean isSwipeRefresh) {
        // TODO Auto-generated method stub
        if (NetUtils.isNetworkConnected(mContext)) {
            mLoginView.showProgress("");
            mInteractor.getRequestData(task_name, url, event_tag, params, header);
        } else {
            mLoginView.closeProgress();
            new HSToast(mContext).showToast(R.string.common_no_network);
        }
    }

    /**
     * header+json
     *
     * @param task_name
     * @param url
     * @param event_tag
     * @param params
     * @param header
     * @param isSwipeRefresh
     */
    @Override
    public void loadingData(String task_name, String url, int event_tag, JSONObject params, HashMap<String, String> header, boolean isSwipeRefresh) {
        if (NetUtils.isNetworkConnected(mContext)) {
            mLoginView.showProgress("");
            mInteractor.getRequestData(task_name, url, event_tag, params, header);
        } else {
            mLoginView.closeProgress();
            new HSToast(mContext).showToast(R.string.common_no_network);
        }
    }

}
